package zj.com.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import zj.com.activities.DqrJcxDetailActivity;
import zj.com.adapter.DqrJcxAdapter;
import zj.com.adapter.DzgSpAdapter;
import zj.com.app.ZjApplication;
import zj.com.model.AuditLog;
import zj.com.model.DjcModel;
import zj.com.model.JcxDB;
import zj.com.model.RecordDetail;
import zj.com.net.NetManager;
import zj.com.net.OnResponseListener;
import zj.com.zj.R;

/**
 * Created by xi on 16/6/4.
 * 待整改 审批
 */
public class DzgDetailSpFragment extends Fragment {


    public ListView listView;
    public List<AuditLog> list;
    public Intent intent;

    public DzgSpAdapter adapter;

    public RelativeLayout error_rl;
    public View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_dzg_detail_sp, container, false);
        initView(view);
        initData();
        return view;
    }


    public void initView(View view){
        this.view = view.findViewById(R.id.view);
        error_rl = (RelativeLayout) view.findViewById(R.id.error_rl);
        listView = (ListView) view.findViewById(R.id.listView);
    }

    public void initData(){

        list = new ArrayList<AuditLog>();
        adapter = new DzgSpAdapter(list,getActivity());
        listView.setAdapter(adapter);


    }

    @Override
    public void onResume() {
        super.onResume();
        obtainData();
    }


    public void obtainData(){


        NetManager.getInstance(getActivity()).GetRiskRepairRecordDetail(ZjApplication.dzgDetailDB.getInspectionID()+"", ZjApplication.dzgInspectItemDB.getInspectContentID()+"", new OnResponseListener<RecordDetail>() {
            @Override
            public void onComplete(boolean isOK,RecordDetail detail, int errorCode, String errorMsg) {


                if(isOK){

                    if(detail != null){

                        List<AuditLog> list = detail.getAuditLog();
                        if(list != null && list.size() > 0){
                            adapter.setDataChange(detail.getAuditLog());
                            error_rl.setVisibility(View.GONE);
                            view.setVisibility(View.VISIBLE);

                        }else{
                            error_rl.setVisibility(View.VISIBLE);
                            view.setVisibility(View.GONE);

                        }
                    }
                }else{
                    Toast.makeText(getActivity(), "获取失败", Toast.LENGTH_SHORT).show();
                    error_rl.setVisibility(View.GONE);
                    view.setVisibility(View.GONE);


                }
            }

            @Override
            public void onInternError(int errorCode, String errorMessage) {
                error_rl.setVisibility(View.GONE);
                view.setVisibility(View.GONE);

                Toast.makeText(getActivity(), "获取失败", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
